package main

import (
	"bufio"
	"fmt"
	"os"
	"svr/src/logs"
	"time"

	"github.com/gorilla/websocket"
)

var dl = &websocket.Dialer{
	ReadBufferSize:   1024,
	WriteBufferSize:  1024,
	HandshakeTimeout: 30 * time.Second,
}

func main() {
	go link()
	link()
}

func send(conn *websocket.Conn) {
	for {
		reader := bufio.NewReader(os.Stdin)
		input, _, _ := reader.ReadLine()
		conn.WriteMessage(1, []byte(input))
	}
}

func link() {

	conn, _, err := dl.Dial("ws://127.0.0.1:20000", nil)
	if err != nil {
		logs.Debugf("", err)
		return
	}
	// conn.WriteMessage(websocket.TextMessage, []byte("你好！！！"))
	go send(conn)
	fmt.Println("-------1111-----------")
	for {
		typ, bs, err := conn.ReadMessage()
		if err != nil {
			break
		}
		fmt.Println(typ, string(bs))
	}
	fmt.Println("-------22222-----------")
}
